package com.jd.basic.exception;

import com.jd.basic.util.AjaxResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice // 对RestControlle增强注解
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class) // 捕捉BusinessException异常
    public AjaxResult businessException(BusinessException e){
        return new AjaxResult(false,e.getMessage());
    }

    @ExceptionHandler(Exception.class) // 捕捉非业务异常
    public AjaxResult globalException(Exception e){
        e.printStackTrace();
        return new AjaxResult(false,ErrorCode.SYSTEM_ERROR.getMessage());
    }
}
